<#include "/base/common/head.html"/>
 
<div id="subLayout" class="easyui-layout" data-options="fit:true, border:false">
	<div id="organDiv" data-options="region:'center',  border:false" >
	   
	    <table id="dg"></table>
	    <div id="tb" style="padding:2px 5px;">
	        <div class="wrap_search">
			        		
	        </div>
	        <div style="text-align: left; margin:6px;">
	        	<!--  
	            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportExcel('all')">导出</a>
	            -->
	            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
	            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
	            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
	            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
	            
	          	
	            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
	                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch()">搜索</a>
	                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
	            </div>
	            
	        </div>
	    </div>
    
    </div>
    <div id="userDiv" data-options="region:'east',split:true, border:false, collapsed:true,  title:'' " style="width:65%;">
    	<iframe id="subIframe" class="easyui-panel" data-options="fit:true,border:false"></iframe>
    </div>
</div> 

<script type="text/javascript">

//数据表格初始化参数
var dgOptions = {
        rownumbers:true, //显示行号
    	fit:true, //自适应父容器
    	border:false, //是否显示面板边框。
    	url:'listData',  //数据请求URL
    	method:'post', //请求方式
    	toolbar:'#tb', //工具栏
    	pageSize: 20, //每页数量
    	pagination:true, //显示分页
    	//fitColumns:true, //自动调整各列宽度。当为true时，各列的宽度值只是一个比例。
    	striped:true, //是否显示斑马线
    	multiSort:false, //是否允许多列排序
		sortName:'orderNum', //初始排序字段
		sortOrder:'asc', //初始排序方式
    	singleSelect: false, //是否单选
		ctrlSelect : true, //启用多选时，允许使用Ctrl键+鼠标进行多选
		showFooter : true, //是否显示行脚
        queryParams: zcurdGetParam(), //请求参数
        onDblClickRow:function(index, row){dbClickShow(row.id);}, //双击行事件
        columns: [[
		         {field:'id', checkbox:true}
	           	 	,{field:'name', title: '名称', width:100, align:'center'   }
	           	 	,{field:'orderNum', title: '排序号', width:80, align:'center'   }
	           	 	,{field:'operate', title: '权限设置', width: 80, align:'center'
		             	,formatter: function(value, row, index){
		             		var html = "";
		             		html += '<a class="operate" href="javascript:void(0)" onclick="btnClick1(' + row.id + ')" style="color:#00F">权限设置</a>';
		     			  	return html;
		     		  	} 
		             }
	           	 
	           ]],
	      loadFilter: function(data) {
	        	   if(data.result && data.result == 'fail') {	//失败时，错误消息提示
	        		   showWarnMsg(data.msg);
	        		   return {};
	        	   }else {
	        		   return data;
	        	   }
	           }           
	};



var datagrid = $("#dg"); //数据表格

$(function() {
	datagrid.datagrid(dgOptions); //绘制数据表格
	autoAddClear(); //为各组件自动填加‘清除’功能（组件需要增加 addClear属性 ）
});

//查询
function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", param)
}

//获取查询参数
function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	//console.log(param);
	return param;
}

var initPara = zcurdGetParam(); //初始化参数，主要目的是保存一些隐藏条件

//增加
function add() {
	top.window.subPage.loadCurrDatagrid = function() { //设置成功后的回调方法
		datagrid.datagrid("load");
	}
	top.openWindow("增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '480x200'});
}

//修改
function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		datagrid.datagrid("reload");
	}
	top.openWindow("编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '480x200'});
}

//详情
function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	dbClickShow(id);
}

//双击打开查看
function dbClickShow(id) {
	top.openWindow_view("详情", getCurrUrl("detailPage") + "?id=" + id, {size: '430x200'});
}

//删除
function del() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据");
		return;
	}
	confirmMsg("确认删除?", function() {
		$.post(getCurrUrl("delete"), {ids: ids.join(",")}, function(data) {
			
			if("01" == data.code){//成功
				datagrid.datagrid("reload");
				showMsg(data.msg); //显示消息
			}else if("04" == data.code){//失败
				showErrorMsg(data.msg); //显示错误消息
			}
			
		});
	});
}


//按钮事件
window.btnClick1 = function(roleId) 
{	
	var url = basePath + "/base/auth/role/editAuthPage?roleId=" + roleId;
	_openSubPage(url);
};

/**
* 打开子页
*/
var _openSubPageFlag = false;
function _openSubPage(pageUrl)
{
	if(!_openSubPageFlag)
	{
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 300);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

//导出Excel
function exportExcel(type) {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sort = option.sortName;
	param.order = option.sortOrder;
	param.type = type;
	window.location.href = "exportExcel?" + $.param(param);
}


/**
 * 格式化函数
 */
 

//类型格式化
function formatType(value)
{
	if(value == null)
	{
		return "";
	}
	return value.name;
};

//Boolean 是否
function formatBoolean1(value)
{
	if(value == null)
	{
		return "";
	}
	if(value)
	{
		return "是";
	}
	return "否";
};

//Boolean 开关
function formatBoolean2(value)
{
	if(value == null)
	{
		return "";
	}
	
	if(value)
	{
		return "开";
	}
	return "关";
};

//类型格式化，不同类型采用不同颜色（参考用）
function formatTypeColor(value)
{
	if(value == null)
	{
		return "";
	}
	if(value.code=='01')
	{
		return "<span style='color:#008B00'>"+value.name+"</span>";
	}
	else if(value.code=='02')
	{
		return "<span style='color:#ff0000'>"+value.name+"</span>";
	}
	else if(value.code=='03')
	{
		return "<span style='color:#20B2AA'>"+value.name+"</span>";
	}
	else if(value.code=='05')
	{
		return "<span style='color:#CDCDB4'>"+value.name+"</span>";
	}
	else if(value.code=='06')
	{
		return "<span style='color:#EEB422'>"+value.name+"</span>";
	}
	return value.name;
};

</script>

<#include "/base/common/dialogWindow.html"/>
<#include "/base/common/foot.html"/>
